package com.mh.example.annotation.cycle;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

public class ExampleBean implements BeanNameAware, BeanFactoryAware, ApplicationContextAware, InitializingBean {

	public void println() {
		System.out.println("annotation >>>This is mh println method.");
	}

	@Override
	public void setBeanName(String name) {
		System.out.println("222 annotation >>> BeanNameAware.setBeanName method. BeanName is 【" + name + "】");
	}

	@Override
	public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
		System.out.println("333 annotation >>> BeanFactoryAware.setBeanFactory");
	}

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		System.out.println("444 annotation >>> ApplicationContextAware.setApplicationContext");
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		System.out.println("666 annotation >>> InitializingBean.afterPropertiesSet");
	}

	@PostConstruct
	public void initMethod() {
		System.out.println("777 annotation >>> ExampleBean.initMethod");
	}

	@PreDestroy
	public void destoryMethod() {
		System.out.println("999 annotation >>> ExampleBean.destoryMethod");
	}

}
